<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>区域管理编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/materialsUnitData.js"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/logic/poquote";
var yd_Url="${ctx}/public/windowalert";
var grid;
$(function(){
	
// 	 $("#kdgs").change(function(){ 
// 			$("#creategsname").val($("#kdgs").find("option:selected").text());
// 			$("#creategscode").val($("#kdgs").val());
// 		}); 
	 
	var column1 = [
					  { display: '<font color="gray">id</font>', name: 'id', width: 1,hide:1 },
					  { display: '<font color="gray">物料id</font>', name: 'materialsid', width: 1,hide:1 },
					  { display: '<font color="gray">物料编码</font>', name: 'materialscode', width: 150 },
	                  { display: '<font color="gray">物料名称</font>', name: 'materialsname', width: 180 },
	                  { display: '<font color="gray">物料类型</font>', name: 'materialstype', width: 100 },
	                  { display: '<font color="gray">规格型号</font>', name: 'materialspec', width: 245 },
	                  { display: '<font color="gray">基本单位</font>', name: 'materialsunit', width: 120/* ,editor : {
	            	 	   type:'selecturl',dataItem:'dataItem',path:'${ctx}/yd/basic/measurementUnit/unitlist.do',valueColumnName: 'unitname', displayColumnName: 'unitname'}, render: function (item)
	            	 	  {
		            	 		  var dataitem = $.parseJSON($("#dataItem").val());
		            	 		  if(dataitem!=null){
		            	 			 for (var i = 0; i < dataitem.length; i++)
		                             {
		                                 if (dataitem[i]['unitname'] == item.materialsunit)
		                                     return dataitem[i]['unitname'];
		                             }
		            	 		  }
		                           return item.materialsunit;
		                       } */},
                       { display: '人民币含税单价<font color="red">*</font>', name: 'taxPrice', width: 120,editor: { type: 'float'},render:function(item){
 	                   	  return (1*item.taxPrice).toFixed(4);
 	                  }},
                       { display: '税率%<font color="red">*</font>', name: 'taxRate', width: 120,editor: { type: 'int'},render:function(item){
                    	   if((item.taxPrice != null && item.taxPrice != NaN)&&(item.taxRate != null && item.taxRate != NaN)){
                    		   grid.updateCell('price', (item.taxPrice-(parseFloat(item.taxPrice)*(item.taxRate/100))).toFixed(4), item); 
                    	   }
	 	                   	  return item.taxRate==null ?item.taxRate:item.taxRate+"";
	 	                  }},    
		               { display: '<font color="gray">人民币不含税单价</font>', name: 'price', width: 120}
		                ];
	              	 	
	var column2 = [
					  { display: '<font color="gray">id</font>', name: 'id', width: 1,hide:1 },
					  { display: '<font color="gray">物料id</font>', name: 'materialsid', width: 1,hide:1 },
					  { display: '<font color="gray">物料编码</font>', name: 'materialscode', width: 150 },
	                  { display: '<font color="gray">物料名称</font>', name: 'materialsname', width: 180 },
	                  { display: '<font color="gray">物料类型</font>', name: 'materialstype', width: 100 },
	                  { display: '<font color="gray">规格型号</font>', name: 'materialspec', width: 245 },
                  { display: '<font color="gray">基本单位</font>', name: 'materialsunit', width: 120},
                  { display: '人民币含税单价<font color="red">*</font>', name: 'taxPrice', width: 120},
                  { display: '税率%<font color="red">*</font>', name: 'taxRate', width: 120},
                  { display: '<font color="gray">人民币不含税单价</font>', name: 'price', width: 120}
                  ];
  var column3 = column1;                 
  if('${poQuoteDOs.billstatus}' != "" && '${poQuoteDOs.billstatus}' != "0"){
  	column3 = column2;    
  }
	var griddata ={};
	if('${poQuoteDOs.billstatus}' != "" && '${poQuoteDOs.billstatus}' != "0"){
		grid = $("#table1").ligerGrid({
	        columns: column3,
	                  enabledEdit: true,
	                  usePager: true,pageSize:1000,pageSizeOptions:[1000],
	                  //data : griddata, 
	                  parms:[{ name : 'id' , value : '${poQuoteDOs.id}'}],
                  	  url : basic_Url+"/griditems.do",
	                  width: "100%", height:180, checkbox: true,
	                  toolbar: { items: [
	                                     { text: '添加物料', icon: 'add' },
	                                     { line: true },
	                                     { text: '删除', img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
	                                     ]
	                                     }
	                  });
	}else{
		grid = $("#table1").ligerGrid({
			columns: column3,
            enabledEdit: true,
            usePager: true,pageSize:1000,pageSizeOptions:[1000],
            //data : griddata,
            parms:[{ name : 'id' , value : '${poQuoteDOs.id}'}],
            url : basic_Url+"/griditems.do",
            width: "100%", height:'90%', checkbox: true,
            toolbar: { items: [
                               { text: '添加物料', click: ItemWindow, icon: 'add' },
                               { line: true },
                               { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
                               ]
                               }
            });
	}
	
	$("#pageloading").hide();

	$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
        	getReturnMessage(basic_Url+"/save.do","inputForm",W.searchAP);
        	W.gysID=$("#gysid").val();
        }catch(e){alert(e)}
    }
	});
	var c =0;
	function cc(){
		c++;
		return c;
	}
	
	if('${poQuoteDOs.billstatus}' != "" && '${poQuoteDOs.billstatus}' != "0"){
		$("input").attr("readonly","readonly");
		$("input").attr("onclick","");
		$("select").attr("disabled","disabled");
	}
	if('${poQuoteDOs.billstatus}' == ""){
		$("#save1").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#bohui").hide();
	}
	else if('${poQuoteDOs.billstatus}' == "0" ){
		if('${user.name}' != '${poQuoteDOs.dcruser}'){
			$("#save1").hide();
		}
		$("#save").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#bohui").hide();
	}
	else if('${poQuoteDOs.billstatus}' == "1" ){
		$("#save1").hide();//禁用保存按钮
		$("#save").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
	}
	else if('${poQuoteDOs.billstatus}' == "2"){
		$("#save1").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#save").hide();//禁用保存按钮
		$("#savej2").hide();
	}
	else{
		$("#save").hide();//禁用保存按钮
		$("#save1").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#savej2").hide();
		$("#bohui").hide();
	}
	
	if ('${flag}' == 'ADD'){
		
	}
	/* if('${poQuoteItemDOs}' != ""){
		<c:forEach items='${poQuoteItemDOs}' var='item'>
    	var manager = $("#table1").ligerGetGridManager();
    	manager.addRow2({
    		id : "${item.id}",
    		materialsid : "${item.materialsid}",
    		materialscode : "${item.materialscode}",
    		materialsname : "${item.materialsname}",
    		materialstype : "${item.materialstype}",
    		materialspec : "${item.materialspec}",
    		materialsunit : "${item.materialsunit}",
    		unitconvert : "${item.unitconvert}",
    		taxPrice : "${item.taxPrice}",
    		taxRate : "${item.taxRate}",
    		price : "${item.price}",
    		
		});
    	</c:forEach>
	} */
	})

	function ItemWindow() {
		getDG().dialog(
				{
					title : '选择材料',
					width : 650,
					height : 350,
					content : 'url:' + sys_context+ '/public/windowalert/itemmanager.do',//
					lock : true,
					max : true,
					min : true,
					ok : function() {
						var getSelectedHub = this.content.getSelected();
						var manager = $("#table1").ligerGetGridManager();
						if (getSelectedHub != null) {
							 $(getSelectedHub).each(function ()
							            {
								                manager.addRow2({
								                materialsid:this.id,
							                	materialscode: this.code,
							                	materialsname: this.name,
							                	materialstype: this.itmetype,
							                	materialspec : this.spec,
							                	taxPrice: this.price,
								                materialsunit:this.unit
							                });
							 });	
							this.content.Close();
						}
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
	}
	


	function deleteRow()
	{ 
		grid.deleteSelectedRow();
	}
	
	function submitForm(param) {
		//设置ajax全局同步
		var data = grid.getData();
		var dl = grid.getDeleted();
		if (data.length == 0) {
			$.dialog.alert("请选择物料");
			return false;
		}
		var ba = true;
		if (data != null) {
			var i = 0;
			$(data).each(function() {
				i++;
				if (isNaN(this.taxPrice) || this.taxPrice== undefined ||this.taxPrice==null) {
					$.dialog.alert("您第" + i + "行的含税单价没有填写!");
					ba = false;
					return false;
				}
				if (this.taxPrice<=0) {
					$.dialog.alert("您第" + i + "行的含税单价不能小于或为0");
					ba = false;
					return false;
				}
				if (isNaN(this.taxRate) ||this.taxRate==undefined || this.taxRate==null) {
					$.dialog.alert("您第" + i + "行的税率没有填写!");
					ba = false;
					return false;
				}
				if (this.taxRate<0) {
					$.dialog.alert("您第" + i + "行的税率不能小于0");
					ba = false;
					return false;
				}
				if (isNaN(this.price) ||this.price==undefined || this.price==null) {
					$.dialog.alert("您第" + i + "行的不含税单价没有填写!");
					ba = false;
					return false;
				}
			});
		}
		jQuery.ajaxSettings.async = false;
		if(param==3){
		getDG().dialog({content: "是否审核完结请选择(Yes或者No)!",width: 250,lock: true,max: false,min: false,
			title:'Confirm Infor',
			button: [
			         {
			             name: 'Yes',
			             callback: function(){
			        		   if (ba) {
			        				$("#type").val(param);
			        				$("#itemdata").val(JSON.stringify(data));
			        				$("#itemdelete").val(JSON.stringify(dl));
			        				$("#inputForm").submit();
			        			}
				            }
			         },
			         {
			        	   name: 'No',
			        	   focus: true
			         }             
			     ]
		}).zindex();
		
		}else{
			if (ba) {
				$("#type").val(param);
				$("#itemdata").val(JSON.stringify(data));
				$("#itemdelete").val(JSON.stringify(dl));
				$("#inputForm").submit();
			}
		}
		
		
	}
	

</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${poQuoteDOs.id}"/>
<input type="hidden" id="itemdata" name="itemdata" value=""/>
<input type="hidden" id="itemdelete" name="itemdelete" value=""/>
<input type="hidden" id="type" name="type" value=""/>
<input type="hidden" id="dataItem" name="dataItem"/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
         <c:if test="${not empty poQuoteDOs.code}">
         		<tr>
   		            <td nowrap>报价单号:</td>
                     <td>
   		                <input type="text" id="code" name="code" class="inp_width_98p" readonly="readonly" value="${poQuoteDOs.code}" />
   		             </td>
                     <td colspan="2">
   		             </td>
   		           </tr>
   		   </c:if>       
   		   <tr>  
   		           <td nowrap>供应商名称:</td>
                     <td>
   		               <input type="hidden" id="gysid" name="gysid" value="${poQuoteDOs.gysid eq null?bcd.id:poQuoteDOs.gysid}" />
   		               <input type="hidden" id="gyscode" name="gyscode" value="${poQuoteDOs.gyscode eq null?bcd.code:poQuoteDOs.gyscode}" />
   		                <input type="text" id="gysName" name="gysName" class="inp_width_98p" readonly="readonly" value="${poQuoteDOs.gysName eq null?bcd.name:poQuoteDOs.gysName}" />
   		             </td>
   		              <td nowrap>供应商地址:</td>
                     <td>
   		                <input type="text" id="gysAddress" name="gysAddress" class="inp_width_98p" readonly="readonly" value="${poQuoteDOs.gysAddress eq null?bcd.address:poQuoteDOs.gysAddress}" />
   		             </td>
   		           </tr>
   		           
   		            <tr>
   		           <td nowrap>供应商联系人:</td>
                     <td>
   		                <input type="text" id="gysLinkman" name="gysLinkman" class="inp_width_98p" readonly="readonly" value="${poQuoteDOs.gysLinkman eq null?bcd.attachperson:poQuoteDOs.gysLinkman}" />
   		             </td>
   		              <td nowrap>供应商电话:</td>
                     <td>
   		                <input type="text" id="gysTel" name="gysTel" class="inp_width_98p" readonly="readonly" value="${poQuoteDOs.gysTel eq null?bcd.telephone:poQuoteDOs.gysTel}" />
   		             </td>
   		           </tr>
   		            <tr>
   		           <td nowrap>供应商手机号:</td>
                     <td>
   		                <input type="text" id="gysPhone" name="gysPhone" class="inp_width_98p" readonly="readonly" value="${poQuoteDOs.gysPhone eq null?bcd.mobil:poQuoteDOs.gysPhone}" />
   		             </td>
   		              <td nowrap>供应商传真:</td>
                     <td>
   		                <input type="text" id="fax" name="fax" class="inp_width_98p" readonly="readonly" value="${poQuoteDOs.fax eq null?bcd.fax:poQuoteDOs.fax}" />
   		             </td>
   		           </tr>
   		           
   		           
   		           
   		           <tr>
   		           <td nowrap>制单人:</td>
                     <td>
   		                <input type="text" id="foundPerson" name="foundPerson" class="required inp_width_98p"  value="${user.name}" readonly="readonly"/>
   		            	<c:if test="${poQuoteDOs.foundPerson != null}">
							<script>
								$("#foundPerson").val("${poQuoteDOs.foundPerson}");
							</script>
						</c:if>
   		             </td>
   		              <td nowrap>询价日期:</td>
                     <td>
   		                <input type="text" id="quoteDate" name="quoteDate"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="required inp_width_98p" value="<fmt:formatDate value="${poQuoteDOs.quoteDate}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly" />
   		             </td>
   		           </tr>
   		           <tr>
                    <td nowrap>交期:</td>
   		                 <td>
   		                <input type="text" id="deliveryTime" name="deliveryTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="required inp_width_98p" value="<fmt:formatDate value="${poQuoteDOs.deliveryTime}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly" />
   		                 </td>
   		                 <td nowrap>报价有效期:</td>
   		                 <td>
   		                <input type="text" id="periodOfValidity" name="periodOfValidity" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="required inp_width_98p" value="<fmt:formatDate value="${poQuoteDOs.periodOfValidity}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly" />
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>付款方式:</td>
   		                <td>
   		                 <select id="fkMode" class="required inp_width_98p"  name="fkMode">
   		                 	<option ></option>
   		                 	<c:forEach items="${modePaymentDOs }" var="modePaymentDOs">
   		                 	<c:choose>
   		                 		<c:when test="${modePaymentDOs.name ==poQuoteDOs.fkMode}">
   		                 			<option value="${modePaymentDOs.name }" selected="selected">${modePaymentDOs.name }</option>
   		                 		</c:when>
   		                 		<c:otherwise>
   		                 			<option value="${modePaymentDOs.name }">${modePaymentDOs.name }</option>
   		                 		</c:otherwise>
   		                 	</c:choose>
   		                 	</c:forEach>
   		                 </select>
   		                </td>
   		                 <td nowrap>交货方式:</td>
   		                 <td>
   		                 <select id="jhMode" class="required inp_width_98p"  name="jhMode">
   		                 <option></option>
   		                 	<c:forEach items="${deliveryDOs }" var="deliveryDOs">
   		                 	<c:choose>
   		                 		<c:when test="${deliveryDOs.name ==poQuoteDOs.jhMode}">
   		                 			<option value="${deliveryDOs.name }" selected="selected">${deliveryDOs.name }</option>
   		                 		</c:when>
   		                 		<c:otherwise>
   		                 			<option value="${deliveryDOs.name }">${deliveryDOs.name }</option>
   		                 		</c:otherwise>
   		                 	</c:choose>
   		                 	</c:forEach>
   		                 </select>
   		                </td>
   		           </tr>
   		           
   		           <tr>
   		            <td nowrap>部门:</td>
                     <td>
                     <select id="depname" class="required inp_width_98p" name="depname">
                     	<option></option>
                     	<c:forEach items="${sDepartmentDOs }" var="sDepartmentDOs">
                     		<option value="${sDepartmentDOs.depname }">${sDepartmentDOs.depname }</option>
                     	</c:forEach>
                     </select>
	                     <script type="text/javascript">
	                     	$("#depname").val('${poQuoteDOs.depname}');
	                     </script>
   		             </td>
   		             
   		              <td nowrap>业务员:</td>
                     <td>
   		               <input type="text" id="salesman" name="salesman" class="required inp_width_98p"  value="${poQuoteDOs.salesman}" />
   		             </td>
   		           </tr>
   		           <tr>
   		              <td nowrap>备注:</td>
                     <td colspan="3">
   		                <input type="text" id="remark" name="remark" class="inp_width_98p"  size="60" value="${poQuoteDOs.remark}" />
   		             </td>
   		           </tr>
                </table>
                <div id="table1"> </div> 
         </div>
         <div class="formBar">
	        <ul>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm(0)">保存</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save1" onclick="submitForm(1)">提交</button></div></div></li>
		       <webres:displaycontroller elementId="CGQUOTE_ZG_CHEECK_PH" description="采购报价单申请驳回">
		       		<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="bohui" onclick="submitForm(9)">驳回</button></div></div></li>
		      	</webres:displaycontroller>
		       <webres:displaycontroller elementId="CGQUOTE_YJ_CHEECK" description="采购报价单二级审核">
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save2" onclick="submitForm(2)">二级审核</button></div></div></li>
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="savej2" onclick="submitForm(3)">二级审核完结</button></div></div></li>
		      		</webres:displaycontroller>
		      		<webres:displaycontroller elementId="CGQUOTE_EJ_CHEECK" description="采购报价单三级审核">
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save3" onclick="submitForm(3)">三级审核</button></div></div></li>
		      		</webres:displaycontroller>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
